package com.ruoyi.specification.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.specification.domain.TStats;
import com.ruoyi.specification.mapper.TSpecificationMapper;
import com.ruoyi.specification.mapper.TStatsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.specification.domain.TSpecification;
import com.ruoyi.specification.service.ITSpecificationService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 实现规格查询Controller
 *
 * @author renyixuan
 * @date 2024-07-25
 */
@RestController
@RequestMapping("/specification")
public class TSpecificationController extends BaseController
{
    @Autowired
    private ITSpecificationService tSpecificationService;
    @Autowired
    TStatsMapper tstatsMapper;

    /**
     * 查询实现规格查询列表
     */
    @RequiresPermissions("specification:specification:list")
    @GetMapping("/list")
    public TableDataInfo list(TSpecification tSpecification)
    {
        startPage();
        List<TSpecification> list = tSpecificationService.selectTSpecificationList(tSpecification);
        return getDataTable(list);
    }


    @GetMapping("/getSpecification")
    public AjaxResult getSpecification(TStats tStats)
    {

        List<TStats> list = tstatsMapper.selectTStatsListByAxuan(tStats);
        return success(list);
    }


    @GetMapping("/getSpeByBargain")
    public AjaxResult getSpeByBargain(TStats tStats)
    {

        List<TStats> list = tstatsMapper.selectTStatsListByBargain(tStats);
        return success(list);
    }

    /**
     * 导出实现规格查询列表
     */
    @RequiresPermissions("specification:specification:export")
    @Log(title = "实现规格查询", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TSpecification tSpecification)
    {
        List<TSpecification> list = tSpecificationService.selectTSpecificationList(tSpecification);
        ExcelUtil<TSpecification> util = new ExcelUtil<TSpecification>(TSpecification.class);
        util.exportExcel(response, list, "实现规格查询数据");
    }

    /**
     * 获取实现规格查询详细信息
     */
    @RequiresPermissions("specification:specification:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {

        return success(tSpecificationService.selectTSpecificationById(Integer.parseInt(id)));
    }

    /**
     * 新增实现规格查询
     */
    @RequiresPermissions("specification:specification:add")
    @Log(title = "实现规格查询", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody TSpecification tSpecification)
    {
        return toAjax(tSpecificationService.insertTSpecification(tSpecification));
    }

    /**
     * 修改实现规格查询
     */
    @RequiresPermissions("specification:specification:edit")
    @Log(title = "实现规格查询", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TSpecification tSpecification)
    {
        return toAjax(tSpecificationService.updateTSpecification(tSpecification));
    }

    /**
     * 删除实现规格查询
     */
    @RequiresPermissions("specification:specification:remove")
    @Log(title = "实现规格查询", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(tSpecificationService.deleteTSpecificationByIds(ids));
    }
}
